package cn.lkk.samples.lang.innerClass;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

/**
 * 演示匿名内部类的使用
 */
public class AnonymousInnerClassTest {
    public static void main(String[] args) {
        TalkingClock2 clock = new TalkingClock2();
        clock.start(1000, true);

        JOptionPane.showMessageDialog(null, "Quit?");
        System.exit(0);
    }

}

class TalkingClock2 {
    public void start(int interval, final boolean beep) {
        Timer timer = new Timer(interval, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Date now = new Date();
                System.out.println("At the tone, the time is " + now);
                if (beep)
                    Toolkit.getDefaultToolkit().beep();
            }
        });
        timer.start();
    }
}
